<template>
	<view class="pages">
		<scroll-view scroll-y="true" class="contentbox" @scrolltolower="scrolltolower">
			<view v-if="list.length == 0">
				<view style="height: 100rpx"></view>
				<u-empty text=" - 暂无数据 - " mode="list"></u-empty>
			</view>
			<view class="boxes" v-for="(item, index) in list" :key="index">
				<view class="flex row-between" @click="call(item.phone)">
					<view class="font-size-30 bold m-b-12">{{item.name}}</view>
					<view class="font-size-30 bold" style="color: #457fd3">{{ item.phone }}</view>
				</view>
				<view>{{item.content?item.content:''}}</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
const app = getApp();
export default {
	data() {
		return {
			is_vip: 0,
			guodao: 0,
			gaosu: 0,
			page: 1,
			limit: 20,
			length: true,
			list: [
				// { id: 1, phone: 13951350471 },
				// { id: 1, phone: 13951350471 }
			]
		};
	},
	onLoad(options) {
		this.is_vip = app.globalData.is_vip;
		if (options.type == 1) {
			this.gaosu = 1;
			uni.setNavigationBarTitle({
				title: '高速护送'
			});
		} else {
			this.gaosu = 1;
			uni.setNavigationBarTitle({
				title: '国道护送'
			});
		}
	},
	async onShow() {
		this.list = [];
		this.page = 1;
		this.limit = 20;
		await this.getList();
	},
	// computed: {
	// 	phonereg: function () {
	// 		return function (phone) {
	// 			phone = phone.toString();
	// 			let reg = /^(\d{3})\d{4}(\d{4})$/;
	// 			let str = phone.replace(reg, '$1****$2');
	// 			return str;
	// 		};
	// 	}
	// },
	methods: {
		call(e) {
			if (!this.is_vip) {
				this.$modal({
					title: '暂无查看和拨打权限!',
					msg: '去获取',
					active: app.globalData.active
				});
				return;
			}
			uni.makePhoneCall({
				// 手机号
				phoneNumber: e + '',
				// 成功回调
				success: (res) => {
					console.log('调用成功!');
				},
				// 失败回调
				fail: (res) => {
					console.log(res);
					console.log('调用失败!');
				}
			});
		},
		// 上拉
		scrolltolower() {
			console.log('触底');
			if (this.length) {
				this.page++;
				this.getList();
			}
		},
		// 列表
		async getList() {
			let res = await this.$api.husong({
				city: uni.getStorageSync('cityCode'),
				guodao: this.guodao,
				gaosu: this.gaosu,
				page_no: this.page,
				page_size: this.limit
			});
			if (res.code == 1) {
				this.length = res.data.lists.length == this.limit;
				this.list.push(...res.data.lists);
			}
		}
	}
};
</script>

<style scoped lang="less">
.pages {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}
.contentbox {
	flex: 1;
	overflow: hidden;
	padding: 20rpx 15rpx;
	box-sizing: border-box;

	.boxes {
		padding: 25rpx 30rpx;
		margin-bottom: 17rpx;
		border-radius: 20rpx;
		border: 1px solid #eee;
	}
}
</style>
